package cc.rengu.igas.cops.core.service.trans.unionpay;

import cc.rengu.igas.channel.upqc.facade.bean.AddnCondition;
import cc.rengu.igas.channel.upqc.facade.bean.PayerInfo;
import cc.rengu.igas.channel.upqc.facade.bean.RiskInfoBean;
import cc.rengu.igas.channel.upqc.facade.request.GenC2BNoRequest;
import cc.rengu.igas.channel.upqc.facade.response.GenC2BNoResponse;
import cc.rengu.igas.channel.upqc.facade.result.Result;
import cc.rengu.igas.cops.common.constant.CopsParamConstant;
import cc.rengu.igas.cops.common.enums.RespCodeEnum;
import cc.rengu.igas.cops.facade.request.BankGenC2BNoRequest;
import cc.rengu.igas.cops.facade.response.BankGenC2BNoResponse;
import cc.rengu.igas.share.common.util.GlobalEsbUtil;
import cc.rengu.igas.share.core.model.UserInfo;
import cc.rengu.igas.share.core.realize.UserService;
import cc.rengu.igas.share.core.realize.impl.UserServiceImpl;
import cc.rengu.oltp.service.base.BizBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.SequenceMapper;
import cc.rengu.oltp.service.common.dao.SignAcctInfoMapper;
import cc.rengu.oltp.service.common.dao.TxnLimitStatisMapper;
import cc.rengu.oltp.service.common.dao.impl.SequenceMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.SignAcctInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.TxnLimitStatisMapperImpl;
import cc.rengu.oltp.service.common.entity.*;
import cc.rengu.oltp.service.common.enums.*;
import cc.rengu.oltp.service.model.*;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.TransCustomImpl;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.base.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;

import java.net.URLEncoder;
import java.util.List;
import java.util.Set;

/**
 * 被扫---银联二维码生成
 * <p>
 * BizStatus：
 * 01-业务处理中
 * 40-授权未完成【待密码认证】
 * 41-授权已完成【密码验证完成】
 * <p>
 * 订单表字段：
 * remark1：预授权状态
 * remark2：被扫上送银联限额
 * remark3：付款人信息
 * frontBackUrl：值为【Speline】时表示是七里堡POS扫码
 * front_seq_num前端流水号：付款凭证号
 * group_mchnt_no：商户号-七里堡扫码时送商户号
 * orig_sys_seq_num：二维码类型
 * need_pay_amt：扫码收款金额
 *
 * @author panky
 * @version 1.0.0 创建时间：2020.06.17
 */
public class BankGenC2BNoService extends BizBaseService implements TransCustomImpl {

    @Override
    protected Object beforeBizProcess() throws Exception {
        BankGenC2BNoRequest bankGenC2BNoRequest = new BankGenC2BNoRequest();
        ConvertUtil.convertOutput(bankGenC2BNoRequest);
        return bankGenC2BNoRequest;
    }

    @Override
    protected BizResponse callBizService(Object request) throws Exception {

        // 录入参数
        BankGenC2BNoRequest bankGenC2BNoRequest = (BankGenC2BNoRequest) request;
        // 行号
        String instId = bankGenC2BNoRequest.getHeader().getInstId();

        SysParamService sysParamService = new SysParamServiceImpl();
        /* 银联码，获取法人行在银联的机构号 */
        SysParam unionPayCode = sysParamService.getSysParamInfo(instId, "OPMS_SYS_PARAM",
                "unionPayerOrgCode" + "_" + bankGenC2BNoRequest.getHeader().getChanlId());
        if (null == unionPayCode) {
            rglog.error("获取二维码服务失败！获取法人行在银联的机构号失败！instId:{}", instId);

            throw new BizException(RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespCode(), RespCodeEnum.MCHNT_INFO_NOT_FOUND.getRespDesc());
        }

        // 根据核心客户号查询出用户
        UserService userService = new UserServiceImpl();
        UserInfo userInfo = userService.getUserInfo(instId, bankGenC2BNoRequest.getHostNo(), bankGenC2BNoRequest.getHeader().getSession());
        if (userInfo == null || !userInfo.getUserStatus().equals("00")) {
            rglog.error("用户不存在,或状态不正确：instId:<{}>,hostNo:<{}>", instId, bankGenC2BNoRequest.getHostNo());
            throw new BizException(RespCodeEnum.USER_STATUS_ABNORMAL.getRespCode(), RespCodeEnum.USER_STATUS_ABNORMAL.getRespDesc());
        }

        // 银联机构号
        String strUnonPayCode = unionPayCode.getParamValue();

        // 生成用户订单
        UserOrderInfo userOrderInfo = initOrderInfoUser(bankGenC2BNoRequest, userInfo);

        /*初始化订单服务*/
        OrderService orderService = new OrderServiceImpl();
        // 调用银联生成二维码
        BankGenC2BNoResponse genC2BNoResponse = genC2BNo(userOrderInfo, bankGenC2BNoRequest, strUnonPayCode, userInfo);
        genC2BNoResponse.setUnid(GlobalEsbUtil.generateEsbSeqeuenceNumber(instId));
        // 生码正常
        if (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(genC2BNoResponse.getRespCode())) {
            /*注册登记订单*/
            if (!orderService.registerOrderInfo(userOrderInfo, null, null)) {
                rglog.error("订单创建失败");
                throw new BizException(RespCodeEnum.INSERT_PAY_ORDER_ERROR.getRespCode(), RespCodeEnum.INSERT_PAY_ORDER_ERROR.getRespDesc());
            }
        }

        // 保留域原路返回
        genC2BNoResponse.setReqReserved(bankGenC2BNoRequest.getReqReserved());
        // 返回
        BizResponse bizResponse = new BizResponse();
        bizResponse.setResult(genC2BNoResponse);// 返回结果
        bizResponse.setRspSysId(AppParamConstant.IGAS);
        bizResponse.setRespCode(genC2BNoResponse.getRespCode());
        bizResponse.setRespDesc(genC2BNoResponse.getRespDesc());
        return bizResponse;
    }

    /**
     * 检查限额
     *
     * @param instId   行号
     * @param userId   用户标识
     * @param userInst 用户所属主体
     * @throws Exception
     */
    private AddnCondition checkLimit(String instId, String userId, String userInst) throws Exception {
        // 附加处理信息
        AddnCondition addnCondition = new AddnCondition();
        /* 获取机构&用户被扫限额 */
        UserService userService = new UserServiceImpl();
        TransLimitInfo transLimitInfo = userService.getUserLimitCfgInfo(instId, userId, userInst, LimitTypeEnum.C2B_QR.getLimitType());
        if (transLimitInfo == null) {
            rglog.error("被扫没有设置限额！");
            throw new BizException(RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespCode(), RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespDesc());
        }

        String strJsonAuth = transLimitInfo.getAuthLimitAmt();
        // 没有设定字段
        if (StringUtil.isNullorEmpty(strJsonAuth)) {
            rglog.error("被扫设置的限额不正确！");
            throw new BizException(RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespCode(), RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespDesc());
        }

        // 遍历认证方式金额区间
        JSONObject authLimitLst = JSON.parseObject(strJsonAuth);
        // 免密限额
        String mianmi[] = authLimitLst.getString("00").split("\\|");
        String maxAmt = "0";
        Set<String> setList = authLimitLst.keySet();
        for (String key : setList) {
            String amtMinMax = (String) authLimitLst.get(key);
            String arr[] = amtMinMax.split("\\|");
            // 获取最大可支付金额
            if (AmountUtil.compare(arr[1], maxAmt) > 0) {
                maxAmt = arr[1];
            }
        }
        // 查询当前已经累计的限额
        TxnLimitStatisMapper txnLimitStatisMapper = new TxnLimitStatisMapperImpl();
        String staticPrimaryKey = LimitTypeEnum.C2B_QR.getLimitType() + userId + "*";
        TxnLimitStatis txnLimitStatis = txnLimitStatisMapper.selectTxnLimitStatisByPrimaryKey(instId, DateUtil.getCurrentDate(), "D", staticPrimaryKey);
        String dayTotalAmt = "0";
        if (txnLimitStatis != null && !StringUtil.isNullorEmpty(txnLimitStatis.getTotalTransAmt())) {
            dayTotalAmt = txnLimitStatis.getTotalTransAmt();
        }
        // 减去已经使用的金额
        String pinFree = AmountUtil.subtraction(mianmi[1], dayTotalAmt);
        if (AmountUtil.compare(pinFree, "0") < 0) {
            pinFree = "0";
        }
        //比较免密日累计限额剩余金额和免密单笔限额大小，免密金额为两者中的最小值
        if (AmountUtil.compare(pinFree, mianmi[2]) == 1) {
            pinFree = mianmi[2];
        }

        // 判断今日消费金额是否大于最大设定限额 ---正常走不到次流程
        if (AmountUtil.compare(maxAmt, dayTotalAmt) < 0) {
            rglog.error("被扫设置的限额超限！");
            throw new BizException(RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespCode(), RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespDesc());
        }

        // 判断业务限额日累计
        if (AmountUtil.compare(transLimitInfo.getDayLimitAmt(), dayTotalAmt) < 0) {
            rglog.error("超过业务单笔限额！");
            throw new BizException(RespCodeEnum.OVER_LIMIT_AMT.getRespCode(), RespCodeEnum.OVER_LIMIT_AMT.getRespDesc());
        }

        //免密金额是否设置为0
        SysParamService sysParamService = new SysParamServiceImpl();
        SysParam sysParam = sysParamService.getSysParamInfo(instId, "OPMS_SYS_PARAM", "upqcZeroPinFreeFlag");
        if (sysParam != null && "1".equals(sysParam.getParamValue())) {
            pinFree = "0.00";
        }

        addnCondition.setPinFree(pinFree);// 以元为单位
        addnCondition.setMaxAmt(maxAmt);
        return addnCondition;
    }

    /**
     * 调用通道--银联，生成二维码
     *
     * @param userOrderInfo       订单表信息
     * @param bankGenC2BNoRequest 录入参数
     * @param strUnonPayCode      银联机构号
     * @return
     */
    private BankGenC2BNoResponse genC2BNo(UserOrderInfo userOrderInfo,
                                          BankGenC2BNoRequest bankGenC2BNoRequest,
                                          String strUnonPayCode,
                                          UserInfo userInfo) throws Exception {

        BankGenC2BNoResponse response = new BankGenC2BNoResponse();
        response.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        response.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        GenC2BNoRequest genC2BNoRequest = new GenC2BNoRequest();

        // 付款方信息	payerInfo
        PayerInfo upPayerBean = new PayerInfo();
        BeanUtil.beanCopy(bankGenC2BNoRequest.getPayerInfo(), upPayerBean);

        upPayerBean.setAccNo(bankGenC2BNoRequest.getPayerInfo().getAccNo());
        upPayerBean.setName(bankGenC2BNoRequest.getPayerInfo().getName());

        genC2BNoRequest.setPayerInfo(upPayerBean);

        SignAcctInfoMapper signAcctInfoMapper = new SignAcctInfoMapperImpl();
        List<SignAcctInfo> signAcctInfoList = signAcctInfoMapper.selectSignAcctInfoBySignAcctNo(bankGenC2BNoRequest.getHeader().getInstId(), bankGenC2BNoRequest.getPayerInfo().getAccNo());
        String turnType = "";
        String errorMsg = "";
        // 没有获取到签约账号，需要给手机返回特定错误码，调整到指定页面
        if (signAcctInfoList == null || signAcctInfoList.isEmpty()) {
            rglog.error("获取签约账号失败，流水号<{}>信息失败,AcctNo:<{}>,ChanlId:<{}>",
                    userOrderInfo.getSysSeqNum(),
                    bankGenC2BNoRequest.getPayerInfo().getAccNo(),
                    bankGenC2BNoRequest.getHeader().getChanlId());
            turnType = "accSign";
            errorMsg = "账号没有签约，现在签约?";
        }
        SignAcctInfo signAcctInfo = signAcctInfoList.get(0);

        // 支付密码为null
        if (StringUtil.isNullorEmpty(turnType)
                && StringUtil.isNullorEmpty(userInfo.getTransPassword())) {
            turnType = "setPwd";
            rglog.error("用户没有设定支付密码,userId:<{}>", userInfo.getUserId());
            errorMsg = "用户未设置密码，请先设置密码";
        }

        if (!StringUtil.isNullorEmpty(turnType)) {
            SysParamService sysParamService = new SysParamServiceImpl();
            /* 手机银行签约地址 */
            SysParam accSignUrl = sysParamService.getSysParamInfo(bankGenC2BNoRequest.getHeader().getInstId(),
                    "OPMS_SYS_PARAM", "ACC_SIGN_URL");
            // 只是签约的话：orderChandlId，userId，mchntNo，payAcctNo，certNo，certType，cardHoldName
            StringBuilder sb = new StringBuilder();
            sb.append("orderChandlId=");
            sb.append(userOrderInfo.getMchntOrderId());
            sb.append("&userId=");
            sb.append(userInfo.getUserId());
            sb.append("&mchntNo=");
            sb.append(AppParamConstant.DEFAULT_INSTID);
            sb.append("&payAcctNo=");
            sb.append(bankGenC2BNoRequest.getPayerInfo().getAccNo());
            sb.append("&certNo=");
            sb.append(userInfo.getCertNo());
            sb.append("&certType=");
            sb.append(userInfo.getCertType());
            sb.append("&cardHoldName=");
            sb.append(userInfo.getUserName());

            SysParam sysParam = sysParamService.getSysParamInfo(AppParamConstant.DEFAULT_INSTID, CopsParamConstant.OPMS_SYS_PARAM, CopsParamConstant.AES_ENC_KEY);
            if (null == sysParam || (null != sysParam && cc.rengu.oltp.utility.util.StringUtil.isEmptyOrNull(sysParam.getParamValue()))) {
                rglog.debug("获取解密密钥串失败");
                throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
            }
            // 代码加密
            String encryptData = AESUtil.pkcs7CbcEncryptData(Base64.decodeBase64(sysParam.getParamValue()), sb.toString().getBytes());
            StringBuilder sbSend = new StringBuilder();
            sbSend.append(accSignUrl.getParamValue());
            sbSend.append("?encryptData=");
            sbSend.append(URLEncoder.encode(encryptData, "UTF-8"));
            sbSend.append("&turnPage=");
            sbSend.append(turnType);
            response.setAccSignUrl(sbSend.toString());

            rglog.debug("手机银行需要跳转{}", response.getAccSignUrl());
            // ER12PM2E
            response.setRespCode(RespCodeEnum.GET_QRCODE_NOT_ACC.getRespCode());
            response.setRespDesc(RespCodeEnum.GET_QRCODE_NOT_ACC.getRespDesc());
            response.setUserErrorMsg(errorMsg);

            return response;
        }

        String payType = PayTypeEnum.BANK_CARD.getPayType();
        // 根据渠道&卡号获取用户号
        // 01 它行，卡号需要转换成协议号
        if ("01".equals(bankGenC2BNoRequest.getCardType())) {
            // 通道签约时，填签约银行联行行号 + "|" + 通道返回的协议号
            String signToken = signAcctInfo.getSignToken().split("|")[1];
            genC2BNoRequest.getPayerInfo().setAccNo(signToken);
            payType = PayTypeEnum.OTHER_BANK_CARD.getPayType();
        }

        // 00-本行卡支付
        // 01-他行卡支付
        JSONObject josnObj = new JSONObject();
        josnObj.put("payType", payType);
        josnObj.put("payerAcctInfo", bankGenC2BNoRequest.getPayerInfo().getAccNo());
        josnObj.put("payerAcctName", bankGenC2BNoRequest.getPayerInfo().getName());
        if (PayTypeEnum.BANK_CARD.getPayType().equals(payType)) {
            //本行卡支付
            if ("01".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
                // 本行 借记卡
                josnObj.put("payerAcctType", AcctTypeEnum.BANK_DEBIT.getAcctType());
            } else if ("02".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
                // 本行 贷记卡
                josnObj.put("payerAcctType", AcctTypeEnum.BANK_CREDIT.getAcctType());
            }
        } else if (PayTypeEnum.OTHER_BANK_CARD.getPayType().equals(payType)) {
            //他行卡支付
            if ("01".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
                // 他行 借记卡
                josnObj.put("payerAcctType", AcctTypeEnum.OTHER_DEBIT.getAcctType());
            } else if ("02".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
                // 他行 贷记卡
                josnObj.put("payerAcctType", AcctTypeEnum.OTHER_CREDIT.getAcctType());
            }
        }
        josnObj.put("transFlag", "0");//支付
        userOrderInfo.setOrderExtraInfo(JSON.toJSONString(josnObj));

        // ChanlId手机和直销、慧济生活等如何区分【应为商户ID】
        AddnCondition addnCondition = checkLimit(bankGenC2BNoRequest.getHeader().getInstId(), userInfo.getUserId(), userInfo.getUserInst());
        // 所有的账户都需要签约，签约账号的用户ID
        userOrderInfo.setUserId(userInfo.getUserId());
        // 二维码限额
        userOrderInfo.setRemark2(JSON.toJSONString(addnCondition));
        //附加条件处理信息	addnCondition
        genC2BNoRequest.setAddnCondition(addnCondition);

        //风控信息	riskInfo
        RiskInfoBean riskInfoBean = new RiskInfoBean();
        BeanUtil.beanCopy(bankGenC2BNoRequest.getRiskInfo(), riskInfoBean);
        genC2BNoRequest.setRiskInfoBean(riskInfoBean);

        //银联机构号	issInsCode
        genC2BNoRequest.setIssInsCode(strUnonPayCode);
        //订单号	orderId
        genC2BNoRequest.setOrderId(userOrderInfo.getSysSeqNum());
        //订单发送时间	orderTime
        genC2BNoRequest.setOrderTime(userOrderInfo.getOrderCreateTime());
        //二维码有效时间
        genC2BNoRequest.setQrValidTime(bankGenC2BNoRequest.getQrValidTime());

        JSONObject reqRJson = new JSONObject();
        reqRJson.put("instId", bankGenC2BNoRequest.getHeader().getInstId());
        reqRJson.put("flowNo", userOrderInfo.getSysSeqNum());
        //请求方保留域	reqReserved
        genC2BNoRequest.setReqReserved(Base64.encodeBase64String(reqRJson.toJSONString().getBytes()));
        // 01-借记
        //  02-贷记
        if ("01".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
            // 35-借记卡
            genC2BNoRequest.setQrType("35");
        } else if ("02".equals(bankGenC2BNoRequest.getPayerInfo().getCardAttr())) {
            genC2BNoRequest.setQrType("51");//51-贷记卡
        } else {
            genC2BNoRequest.setQrType("40");//40－其他
        }

        cc.rengu.igas.channel.upqc.facade.base.Header upHeader = new cc.rengu.igas.channel.upqc.facade.base.Header();
        BeanUtil.beanCopy(bankGenC2BNoRequest.getHeader(), upHeader);

        upHeader.setTxnNum("0210000903");// 查询订单
        upHeader.setSrcSysId("OPMS");
        genC2BNoRequest.setHeader(upHeader);
        // 调用通道获取二维码
        DubboService dubboService = new DubboServiceImpl();
        Result<GenC2BNoResponse> responseResult = (Result<GenC2BNoResponse>) dubboService.callDubboService("upqcPayerService", "genC2BNo", genC2BNoRequest);
        if (null == responseResult || !responseResult.isSuccess() || !"00000000".equals(responseResult.getResult().getRespCode())) {
            rglog.error("调用银联获取二维码失败，二维码<{}>信息失败,iReturnCode:<{}>", userOrderInfo.getSysSeqNum(),
                    responseResult.getResult().getRespCode());
            throw new BizException(RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespCode(), RespCodeEnum.GET_QRCODE_INFO_ERROR.getRespDesc());
        }

        GenC2BNoResponse genC2BNoResponse = responseResult.getResult();
        // 银联二维码编号
        userOrderInfo.setOrderUrl(genC2BNoResponse.getQrNo());
        response.setQrNo(genC2BNoResponse.getQrNo());
        response.setQrValidTime(genC2BNoResponse.getQrValidTime());
        return response;
    }

    /**
     * 登记用户订单表
     *
     * @throws Exception 异常
     */
    private UserOrderInfo initOrderInfoUser(BankGenC2BNoRequest bankGenC2BNoRequest, UserInfo userInfo) throws Exception {

        UserOrderInfo userOrderInfo = new UserOrderInfo();
        userOrderInfo.setInstId(bankGenC2BNoRequest.getHeader().getInstId());// 机构标识
        userOrderInfo.setTxnDate(DateUtil.getCurrentDate());// 交易日期
        userOrderInfo.setTxnTime(DateUtil.getCurrentTime());// 交易时间
        userOrderInfo.setTxnNum(bankGenC2BNoRequest.getHeader().getTxnNum());// 内部交易码
        userOrderInfo.setBizType(bankGenC2BNoRequest.getHeader().getBizType());// 业务细分
        userOrderInfo.setMsgSrcId(bankGenC2BNoRequest.getHeader().getSrcSysId());// 源系统标识
        // 交易渠道--行级别的--使用行号
        String sysNum = generateTransSeqNum();
        userOrderInfo.setTransChannelId(bankGenC2BNoRequest.getHeader().getInstId());// 交易渠道标识
        // 手机退款的时候展现的流水号是商户订单号，但是商户平台扫的事订单流水号，被扫设定成一样的，不会出现无法退款情况。
        userOrderInfo.setMchntOrderId(sysNum); // 商户订单号不存子啊，使用系统流水号
        userOrderInfo.setSysSeqNum(sysNum);// 系统流水号
        userOrderInfo.setUserId(userInfo.getUserId());//核心客戶號
        userOrderInfo.setOrderCreateTime(DateUtil.getCurrentDateTime("yyyyMMddHHmmss"));// 订单创建时间

        // 有效时间
        String qrValidTime = bankGenC2BNoRequest.getQrValidTime();
        if (StringUtil.isNullorEmpty(qrValidTime)) {
            // 默认是3分钟
            qrValidTime = "180";
        }
        int iQrValidTime = Integer.parseInt(qrValidTime);
        // 订单有效时间
        userOrderInfo.setOrderExpiryTime(DateUtil.getDateByTimeStamp(System.currentTimeMillis() + iQrValidTime * 1000, "yyyyMMddHHmmss"));
        userOrderInfo.setOrderStatus(OrderStatusEnum.INIT.getStatus());
        userOrderInfo.setTransStatus(TransStatusEnum.TRANS_INIT.getStatus());
        // 01-业务处理中 40-授权未完成【待密码认证】
        userOrderInfo.setBizStatus(BizStatusEnum.PROCESSING.getStatus());
        userOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        userOrderInfo.setRemark3(JSON.toJSON(bankGenC2BNoRequest.getPayerInfo()).toString());// 付款信息
        return userOrderInfo;
    }

    @Override
    protected void afterBizProcess(BizResponse response) throws Exception {
        BankGenC2BNoResponse bankGenC2BNoResponse = (BankGenC2BNoResponse) response.getResult();
        ConvertUtil.convertInput(bankGenC2BNoResponse);
    }

    @Override
    protected RiskMonitorInfo getRiskMonitorInfo() {
        return null;
    }

    /**
     * 生成交易流水号--30位
     *
     * @throws Exception 业务异常
     */
    private String generateTransSeqNum() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String msgSrcId = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.MSG_SRC_ID);
        SequenceMapper sequenceMapper = new SequenceMapperImpl();
        String transSeqNo = sequenceMapper.getNextTransSequenceNo(8);
        if (null == transSeqNo) {
            rglog.error("生成交易流水序列号失败!");
            throw new BizException(OltpRpcdEnum.GENERATE_SEQUENCE_ERROR);
        }
        /* 流水号规则：6位渠道标识 + 8位日期 + 6位时间 + 2位数据库服务器集群标识 + 6位序号 */
        if (msgSrcId.length() < 6) {
            String format = "%0" + (6 - msgSrcId.length()) + "d";
            msgSrcId = msgSrcId + String.format(format, 0);
        } else {
            msgSrcId = msgSrcId.substring(0, 6);
        }
        String sysSeqNum = msgSrcId + DateUtil.getCurrentDate() + DateUtil.getCurrentTime() + AppParamConstant.CLUSERT_ID + transSeqNo;
        // 不更新xml树，更新后日志会变更
        // xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM, sysSeqNum);
        return sysSeqNum;
    }

    @Override
    public ChannelCallCfg channelCallSceneDiscern(Object request, List<ChannelCallCfg> channelCallCfgList) throws Exception {
        return null;
    }

    @Override
    public CheckResultEnum channelCallPreCheck(Object request, ChannelCallCfg channelCallCfg, OrderInfo orderInfo) throws Exception {
        return null;
    }

    @Override
    public TransStatusEnum channelCallResultProc(Object request, ChannelCallCfg channelCallCfg, TransStatusEnum transStatusEnum, Object channelResponse, OrderInfo needUpdateOrderInfo) throws Exception {
        return null;
    }
}
